package com.myk.game.gobangchess.ai.shock;

public class Pointsetting {

    public static int[][] pointsetting(int[][] board, int x, int y) {
        int[][] newBoard = new int[8][8];
        copyBoard(board, newBoard);

        for (int i = 0; i < 8; i++) {
            int yBeside = y + drictions[i][0] + 1;
            int yFar = y + 2 * drictions[i][0]+ 1;
            int xBeside = x + drictions[i][1]+ 1;
            int xFar = x + 2 * drictions[i][1]+ 1;

            if (yFar >= 1 && yFar <= 8 && xFar >= 1 && xFar <= 8) {
                if (newBoard[yBeside - 1][xBeside - 1] != 0 && newBoard[yFar - 1][xFar - 1] == 0) {
                    newBoard[yFar - 1][xFar - 1] = newBoard[yBeside - 1][xBeside - 1];
                    newBoard[yBeside - 1][xBeside - 1] = 0;
                }
            } else if (yBeside >= 1 && yBeside <= 8 && xBeside >= 1 && xBeside <= 8) {
                if (board[yBeside - 1][xBeside - 1] != 0) {
                    newBoard[yBeside - 1][xBeside - 1] = 0;
                }
            }
        }

        return newBoard;
    }

    private static void copyBoard(int[][] source, int[][] destination) {
        for (int i = 0; i < source.length; i++) {
            System.arraycopy(source[i], 0, destination[i], 0, source[i].length);
        }
    }

    private static final int[][] drictions = {{-1, 0}, {1, 0}, {-1, -1}, {1, 1}, {1, -1}, {-1, 1}, {0, 1}, {0, -1}};
}
